package com.oromwin.repos.server.response.file;

import java.io.DataOutputStream;
import java.io.IOException;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.helper.IOHelper;
import com.oromwin.repos.data.FileTable;
import com.oromwin.repos.server.response.NormalResponse;

public class InfoFileResponse extends NormalResponse {
    private Log log = Logger.getLog(InfoFileResponse.class);
    private FileTable fileTable = null;

    public InfoFileResponse(boolean result, String description, FileTable fTable) {
        Result = result;
        Description = description;
        fileTable = fTable;
    }

    public void send(DataOutputStream dos) throws ReposException {
        try {
            dos.writeBoolean(Result);
            IOHelper.writeUTF8(dos, Description.toString());
            IOHelper.writeUTF8(dos, fileTable.getVolumeId());
            IOHelper.writeUTF8(dos, fileTable.getMediaId());
            IOHelper.writeUTF8(dos, fileTable.getFileId());
            IOHelper.writeUTF8(dos, fileTable.getFileName());
            IOHelper.writeUTF8(dos, fileTable.getFileFormat());
            IOHelper.writeUTF8(dos, fileTable.getFilePath().toString());
            dos.writeLong(fileTable.getFileBytes());
            IOHelper.writeUTF8(dos, fileTable.getFileCategory());
            dos.writeBoolean(fileTable.getFileStatus());
            dos.writeBoolean(fileTable.getFilePdfConvFlag());
            dos.writeBoolean(fileTable.getFileCompressionFlag());
            IOHelper.writeUTF8(dos, fileTable.getFileCreateDate());
            IOHelper.writeUTF8(dos, fileTable.getFileUpdateDate());
        } catch (IOException e) {
            throw ReposException.create(log, e);
        }
    }
}
